package com.hzz.service.analysis;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzz.api.analysis.IAnalysisEventComplaintService;
import com.hzz.dao.analysis.IAnalysisEventComplaintDao;
import com.hzz.dto.analysis.AnalysisEventComplaintDto;
import com.hzz.entity.analysis.AnalysisEventComplaint;
import com.hzz.framework.SysErrorCode;
import com.hzz.framework.exception.ServiceException;
import com.hzz.framework.service.BaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class AnalysisEventComplaintService extends BaseService implements IAnalysisEventComplaintService {
    @Autowired
    IAnalysisEventComplaintDao analysisEventComplaintDao;

    @Override
    public PageInfo analysisNumberByAreaIsPage(AnalysisEventComplaintDto dto) {
        PageInfo pageInfo = null;
        try {
            AnalysisEventComplaint entity = copyTo(dto, AnalysisEventComplaint.class);
            PageHelper.startPage(PN(dto.getPageNum()), PS(dto.getPageSize()));
            List list = analysisEventComplaintDao.analysisNumberByArea(entity);
            pageInfo = new PageInfo(list);
            pageInfo.setList(copyTo(pageInfo.getList(), AnalysisEventComplaintDto.class));
        } catch (Exception e) {
            log.error("处理数量 分页。异常!", e);
            throw new ServiceException(SysErrorCode.defaultError, e);
        }
        return pageInfo;
    }

    @Override
    public List<AnalysisEventComplaintDto> analysisNumberByArea(AnalysisEventComplaintDto dto) {
        List<AnalysisEventComplaintDto> results = null;
        try {
            AnalysisEventComplaint entity = copyTo(dto, AnalysisEventComplaint.class);
            results = copyTo(analysisEventComplaintDao.analysisNumberByArea(entity), AnalysisEventComplaintDto.class);
        } catch (Exception e) {
            log.error("处理数量 列表。异常!", e);
            throw new ServiceException(SysErrorCode.defaultError, e);
        }
        return results;
    }

    @Override
    public List<AnalysisEventComplaintDto> analysisTypeByArea(AnalysisEventComplaintDto dto) {
        List<AnalysisEventComplaintDto> results = null;
        try {
            AnalysisEventComplaint entity = copyTo(dto, AnalysisEventComplaint.class);
            results = copyTo(analysisEventComplaintDao.analysisTypeByArea(entity), AnalysisEventComplaintDto.class);
        } catch (Exception e) {
            log.error("处理类型 列表。异常!", e);
            throw new ServiceException(SysErrorCode.defaultError, e);
        }
        return results;
    }

    @Override
    public List<AnalysisEventComplaintDto> statsComplaint(AnalysisEventComplaintDto dto) {
        List<AnalysisEventComplaintDto> results = null;
        try {
            AnalysisEventComplaint entity = copyTo(dto, AnalysisEventComplaint.class);
            results = copyTo(analysisEventComplaintDao.statsComplaint(entity), AnalysisEventComplaintDto.class);
        } catch (Exception e) {
            log.error("公共投诉 列表。异常!", e);
            throw new ServiceException(SysErrorCode.defaultError, e);
        }
        return results;
    }
}